package com.chanjiedata.changbs.module.main;

/**
 * 文件名 : ShareProfitActivity
 * 创建者 : MangoWang
 * 创建日期 : 2019/12/3 14:28
 * 微信 : MangoWaWang
 * 邮箱 : 763482205@qq.com
 * 描述 : TODO
 */

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chanjiedata.changbs.R;
import com.chanjiedata.changbs.base.BaseActivity;
import com.chanjiedata.changbs.net.Apis;
import com.chanjiedata.changbs.net.NetworkManager;
import com.chanjiedata.changbs.net.interfaces.OnRequestCallBack;
import com.chanjiedata.changbs.proto.Mystock;
import com.chanjiedata.changbs.utlis.StatusBarUtil;
import com.chanjiedata.changbs.utlis.ValidateUtils;
import com.google.protobuf.InvalidProtocolBufferException;
import com.ruffian.library.widget.RTextView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ShareProfitActivity extends BaseActivity {


    @BindView(R.id.back_tv)
    TextView backTv;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.tv_company_name)
    TextView tvCompanyName;
    @BindView(R.id.tv_goods_name)
    TextView tvGoodsName;
    @BindView(R.id.tv_cloud_pay)
    TextView tvCloudPay;
    @BindView(R.id.tv_credit_card)
    TextView tvCreditCard;
    @BindView(R.id.tv_bank_card)
    TextView tvBankCard;
    @BindView(R.id.tv_fast_pay)
    TextView tvFastPay;
    @BindView(R.id.tv_code_pay)
    TextView tvCodePay;
    @BindView(R.id.tv_bank_card_top)
    TextView tvBankCardTop;
    @BindView(R.id.tv_machine_award)
    TextView tvMachineAward;
    @BindView(R.id.tv_recommend_award)
    TextView tvRecommendAward;

    @BindView(R.id.rv_recommend_say)
    RelativeLayout rvRecommendSay;
    @BindView(R.id.tv_recommend_say)
    RTextView tvRecommendSay;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_share_profit);
        ButterKnife.bind(this);
        StatusBarUtil.setStatusBarLightMode(this, Color.parseColor("#ffffff"), true);
        tvTitle.setText(getIntent().getStringExtra("title"));
        initListener();
        initData();
    }

    private void initData() {
        Mystock.MyProductRateInfo.Builder builder = Mystock.MyProductRateInfo.newBuilder();
        builder.setGoodsId(getIntent().getStringExtra("goods_id"));
        String others_member_id = getIntent().getStringExtra("others_member_id");
        if (!TextUtils.isEmpty(others_member_id)) {
            builder.setOthersMemberId(others_member_id);
        }
        NetworkManager.INSTANCE.post(Apis.myProductRateInfo, builder.build().toByteArray(), new OnRequestCallBack() {
            @Override
            public void onOk(byte[] response) throws InvalidProtocolBufferException {
                String des = Mystock.MyProductRateInfo.parseFrom(response).getDes();
                Mystock.MyProductRateInfo.MRateInfo data = Mystock.MyProductRateInfo.parseFrom(response).getMRateInfo();
                tvCompanyName.setText(data.getGcName());
                tvGoodsName.setText(data.getGoodsName() + data.getGoodsSerial());
                tvCloudPay.setText(data.getCloudAdminShare() + "%");
                tvCreditCard.setText(data.getLineCardAdminShare() + "%");
                tvBankCard.setText(data.getBankCardAdminShare() + "%");
                tvFastPay.setText(data.getQuickPayAdminShare() + "%");
                tvCodePay.setText(data.getScaveCodeAdminShare() + "%");
                tvBankCardTop.setText(data.getBankCardAdminShareTop());
                tvMachineAward.setText(data.getActivateRewards());
                tvRecommendAward.setText(data.getGoodsRewards());
                if (ValidateUtils.isValidate(des)) {
                    tvRecommendSay.setText(des);
                } else {
                    rvRecommendSay.setVisibility(View.GONE);
                }

            }

            @Override
            public void onError(int errorCode, String errorMessage) {

            }
        });
    }


    private void initListener() {
        backTv.setOnClickListener(view -> {
            finish();
        });
    }


}
